package net.panda.pandatools;


import java.util.List;

import android.hardware.Camera;
import android.hardware.Camera.Parameters;

public class LedLight {
	Camera mCamera;
	
	public LedLight(){
		
	}
	
	public void turnOn() {
		try {
			
			mCamera = Camera.open();
            final Parameters params = mCamera.getParameters();

            List<String> flashModes = params.getSupportedFlashModes();

            if (flashModes == null) {
                return;
            } else {
                params.setFlashMode(Parameters.FLASH_MODE_OFF);
                mCamera.setParameters(params);
                mCamera.startPreview();

                String flashMode = params.getFlashMode();

                if (!Parameters.FLASH_MODE_TORCH.equals(flashMode)) {

                    if (flashModes.contains(Parameters.FLASH_MODE_TORCH)) {
                        params.setFlashMode(Parameters.FLASH_MODE_TORCH);
                        mCamera.setParameters(params);
                    } else {
                        // Toast.makeText(this,
                        // "Flash mode (torch) not supported",Toast.LENGTH_LONG).show();

                        params.setFlashMode(Parameters.FLASH_MODE_ON);

                        mCamera.setParameters(params);
                    }
                }
            }
		
		} catch (Exception x){
			x.printStackTrace();
		}
	}
	
	public void turnOff() {
        if (mCamera != null) {
        	Parameters p = mCamera.getParameters();
        	p.setFlashMode(Parameters.FLASH_MODE_OFF);
        	mCamera.setParameters(p);
        	mCamera.stopPreview();		
        	mCamera.release();
        }

	}	
	
	
}
